package com.ruoyi.life.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.omp.api.domain.FeFacility;
import com.ruoyi.life.service.IFeFacilityService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设施费用Controller
 *
 * @author cjie
 * @date 2021-09-17
 */
@Api(tags = " 设施费用")
@RestController
@RequestMapping("/feFacility")
public class FeFacilityController extends BaseController {
    @Autowired
    private IFeFacilityService feFacilityService;

    /**
     * 查询设施费用列表
     */
    @ApiOperation(value="查询设施费用列表", notes="查询设施费用列表")
    @PreAuthorize(hasPermi = "life:feFacility:list")
    @GetMapping("/list")
    public TableDataInfo list(FeFacility feFacility) {
        startPage();
        List<FeFacility> list = feFacilityService.selectFeFacilityList(feFacility);
        return getDataTable(list);
    }

    /**
     * 导出设施费用列表
     */
    @ApiOperation(value="导出设施费用列表", notes="导出设施费用列表")
    @PreAuthorize(hasPermi = "life:feFacility:export")
    @Log(title = "设施费用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FeFacility feFacility) throws IOException {
        List<FeFacility> list = feFacilityService.selectFeFacilityList(feFacility);
        ExcelUtil<FeFacility> util = new ExcelUtil<FeFacility>(FeFacility.class);
        util.exportExcel(response, list, "设施费用数据");
    }
    /**
     * 获取设施费用详细信息
     */
    @ApiOperation(value="获取设施费用详细信息", notes="获取设施费用详细信息")
    @PreAuthorize(hasPermi = "life:feFacility:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(feFacilityService.selectFeFacilityById(id));
    }

    /**
     * 新增设施费用
     */
    @ApiOperation(value="新增设施费用", notes="新增设施费用")
    @PreAuthorize(hasPermi = "life:feFacility:add")
    @Log(title = "设施费用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeFacility feFacility) {
        return toAjax(feFacilityService.insertFeFacility(feFacility));
    }

    /**
     * 修改设施费用
     */
    @ApiOperation(value="修改设施费用", notes="修改设施费用")
    @PreAuthorize(hasPermi = "life:feFacility:edit")
    @Log(title = "设施费用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeFacility feFacility) {
        return toAjax(feFacilityService.updateFeFacility(feFacility));
    }

    /**
     * 删除设施费用
     */
    @ApiOperation(value="删除设施费用", notes="删除设施费用")
    @ApiImplicitParam(name = "ids", value = "设施费用ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "life:feFacility:remove")
    @Log(title = "设施费用", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(feFacilityService.deleteFeFacilityByIds(ids));
    }
}
